﻿using System;
using BrainTechLLC;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace BrainTechLLC.Silverlight.ClientApplication
{
    public partial class EditAssociatedID : UserControl
    {
        public event EventHandler<ObjectEventArgsNonRef<long>> RequestEditID;

        public static readonly DependencyProperty AssociatedIDProperty = DependencyProperty.Register(
            "AssociatedID",
            typeof(long),
            typeof(EditAssociatedID),
            new PropertyMetadata((long)0, new PropertyChangedCallback(AssociatedIDChanged)));

        public long AssociatedID
        {
            get { return (long)GetValue(AssociatedIDProperty); }
            set { SetValue(AssociatedIDProperty, value); }
        }

        private static void AssociatedIDChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            EditAssociatedID t = (EditAssociatedID)d;
            t.AssociatedID = (long)e.NewValue;
            t.txtID.Text = t.AssociatedID.ToString();
        }

        public EditAssociatedID()
        {
            // Required to initialize variables
            InitializeComponent();
        }

        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtID.Text))
                return;

            if (RequestEditID != null)
                RequestEditID(this, new ObjectEventArgsNonRef<long>(txtID.Text.Long()));
        }
    }
}